07/01/2021

Objective

The objective of this presentation is to present the Covid cases data from Open Toronto using the Plotly package.

Installing Packages

The following code is used to install the necessary packages

install.packages("opendatatoronto", repos = "http://cran.us.r-project.org",
                 dependencies = TRUE)
library(opendatatoronto)
library(dplyr)
library(plotly)

Load Data

The following code is used to download the data as provided by the Open Toronto Database:

# get package
package <- show_package("64b54586-6180-4485-83eb-81e8fae3b8fe")

# get all resources for this package
resources <- list_package_resources("64b54586-6180-4485-83eb-81e8fae3b8fe")
datastore_resources <- filter(resources, tolower(format) %in%
                                      c('csv', 'geojson'))
    
# load the first datastore resource as a sample
data <- filter(datastore_resources, row_number()==1) %>% get_resource()

Data cleaning

The following code is used to clean and present the data

data$`Reported Date` <- as.Date(data$`Reported Date`)
data2 <- data %>% count(`Reported Date`, `Age Group`)
names(data2)[3] <- "Count"
plot1 <- plot_ly(data = data2, y = ~Count, x = ~`Reported Date`,
                 color = ~`Age Group`, type = "scatter")

The final plot will be on the next slide

Plotly Plot